package com.zhipu.balance.utils.data

import android.text.TextUtils
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.TimeUtils
import com.zhipu.balance.mobile.event.*
import com.zhipu.balance.utils.CommonUtils

/**
 * 平均值
 */
object AverageValueUtils {
    /**
     * 稻谷计算平均值
     */
    fun AverageValueRice(mRecordRiceList: List<RecordRice>) : RecordRice{
        var mRecordRice = RecordRice()
        var length = 0
        for (recordRice in mRecordRiceList){
            /**
             * 是否选中
             */
            if(recordRice.select){
                length ++
                /**
                 * 唯一识别码
                 */
                mRecordRice.uniqueId = recordRice.uniqueId

                /**
                 * 检测日期时间戳精确到毫秒 13位
                 */
                mRecordRice.inspectionDate = TimeUtils.getNowMills()

                /**
                 * 设备码
                 */
                mRecordRice.deviceId = recordRice.deviceId

                /**
                 * 杂质记录员
                 */
                if(!TextUtils.isEmpty(recordRice.impurityRecorder)){
                    /**
                     * 是否杂质平均值
                     */
                    mRecordRice.impurityAverageValue = true
                    /**
                     * 大样试验-试样质量
                     */
                    mRecordRice.largeMiscellaneousSampleQuality = (recordRice.largeMiscellaneousSampleQuality + mRecordRice.largeMiscellaneousSampleQuality)
                    /**
                     * 大样试验-杂质
                     */
                    mRecordRice.detailImpurity = (recordRice.detailImpurity + mRecordRice.detailImpurity);
                    /**
                     * 大样杂质率
                     */
                    mRecordRice.detailResults = (recordRice.detailResults + mRecordRice.detailResults)
                    /**
                     * 小样试验-试样质量
                     */
                    mRecordRice.smallMiscellaneousSampleQuality = (recordRice.smallMiscellaneousSampleQuality + mRecordRice.smallMiscellaneousSampleQuality)
                    /**
                     * 小样试验-杂质
                     */
                    mRecordRice.smallSampleImpurity = (recordRice.smallSampleImpurity + mRecordRice.smallSampleImpurity)
                    /**
                     * 小样杂质率
                     */
                    mRecordRice.sampleResults = (recordRice.sampleResults + mRecordRice.sampleResults)
                    /**
                     * 总杂质率
                     */
                    mRecordRice.impurityResults = (recordRice.impurityResults + mRecordRice.impurityResults)
                    /**
                     * 杂质记录员
                     */
                    mRecordRice.impurityRecorder = recordRice.impurityRecorder
                }
                if(!TextUtils.isEmpty(recordRice.rougheningRecorder)){
                    /**
                     * 是否出糙率平均值
                     */
                    mRecordRice.roughnessRateAverageValue = true
                    /**
                     * 出糙率-试样质量
                     */
                    mRecordRice.roughSampleQuality = (recordRice.roughSampleQuality + mRecordRice.roughSampleQuality)
                    /**
                     * 完整糙米质量
                     */
                    mRecordRice.brownRiceQuality = (recordRice.brownRiceQuality + mRecordRice.brownRiceQuality)
                    /**
                     * 不完善糙米质量
                     */
                    mRecordRice.incompleteBrownRiceQuality = (recordRice.incompleteBrownRiceQuality + mRecordRice.incompleteBrownRiceQuality)
                    /**
                     * 出糙率-结果
                     */
                    mRecordRice.rougheningResults = (recordRice.rougheningResults + mRecordRice.rougheningResults)
                    /**
                     * 出糙率记录员
                     */
                    mRecordRice.rougheningRecorder = recordRice.rougheningRecorder
                }
                if(!TextUtils.isEmpty(recordRice.headRiceRecorder)){
                    /**
                     * 是否整精米平均值
                     */
                    mRecordRice.milledRiceAverageValue = true
                    /**
                     * 整精米率-试样质量
                     */
                    mRecordRice.qualityOfMilledRiceSample = (recordRice.qualityOfMilledRiceSample + mRecordRice.qualityOfMilledRiceSample)
                    /**
                     * 整精米质量
                     */
                    mRecordRice.headRiceQuality = (recordRice.headRiceQuality + mRecordRice.headRiceQuality)
                    /**
                     * 整精米率-结果
                     */
                    mRecordRice.headRiceResult = (recordRice.headRiceResult + mRecordRice.headRiceResult)
                    /**
                     * 整精米率记录员
                     */
                    mRecordRice.headRiceRecorder = recordRice.headRiceRecorder
                }
                if(!TextUtils.isEmpty(recordRice.brownRiceRecorder)){
                    /**
                     * 是否谷外糙平均值
                     */
                    mRecordRice.ExternalValleyRoughnessAverageValue = true
                    /**
                     * 谷外糙米-试样质量
                     */
                    mRecordRice.qualityOfBrownRiceSample = (recordRice.qualityOfBrownRiceSample + mRecordRice.qualityOfBrownRiceSample)
                    /**
                     * 谷外糙米-糙米质量
                     */
                    mRecordRice.outsideBrownRiceQuality = (recordRice.outsideBrownRiceQuality + mRecordRice.outsideBrownRiceQuality)
                    /**
                     * 谷外糙米-结果
                     */
                    mRecordRice.brownRiceResult = (recordRice.brownRiceResult + mRecordRice.brownRiceResult)
                    /**
                     * 谷外糙米记录员
                     */
                    mRecordRice.brownRiceRecorder = recordRice.brownRiceRecorder
                }
                if(!TextUtils.isEmpty(recordRice.yellowGrainRiceRecorder)){
                    /**
                     * 是否黄粒米平均值
                     */
                    mRecordRice.YellowGrainRiceAverageValue = true
                    /**
                     * 黄粒米-试样质量
                     */
                    mRecordRice.yellowGrainRiceSampleQuality = (recordRice.yellowGrainRiceSampleQuality + mRecordRice.yellowGrainRiceSampleQuality)
                    /**
                     * 黄粒米质量
                     */
                    mRecordRice.yellowGrainRiceQuality = (recordRice.yellowGrainRiceQuality + mRecordRice.yellowGrainRiceQuality)
                    /**
                     * 黄粒米率
                     */
                    mRecordRice.yellowGrainRiceResult = (recordRice.yellowGrainRiceResult + mRecordRice.yellowGrainRiceResult)
                    /**
                     * 黄粒米记录员
                     */
                    mRecordRice.yellowGrainRiceRecorder = recordRice.yellowGrainRiceRecorder
                }
                if(!TextUtils.isEmpty(recordRice.mixedGrainRecorder)){
                    /**
                     * 是否互混平均值
                     */
                    mRecordRice.intermixingAverageValue = true
                    /**
                     * 互混-试样质量
                     */
                    mRecordRice.massOfMixedSample = (recordRice.massOfMixedSample + mRecordRice.massOfMixedSample);
                    /**
                     * 异种粮质量
                     */
                    mRecordRice.mixedGrainQuality = (recordRice.mixedGrainQuality + mRecordRice.mixedGrainQuality);
                    /**
                     * 互混-结果
                     */
                    mRecordRice.mixedGrainResult = (recordRice.mixedGrainResult + mRecordRice.mixedGrainResult);
                    /**
                     * 互混记录员
                     */
                    mRecordRice.mixedGrainRecorder = recordRice.mixedGrainRecorder
                }
                if(!TextUtils.isEmpty(recordRice.yieldRateRecorder)){
                    /**
                     * 是否出米平均值
                     */
                    mRecordRice.RiceOutputAverageValue = true
                    /**
                     * 总稻谷量
                     */
                    mRecordRice.totalPaddyQuality = (recordRice.totalPaddyQuality + mRecordRice.totalPaddyQuality);
                    /**
                     * 出米量
                     */
                    mRecordRice.riceQuality = (recordRice.riceQuality + mRecordRice.riceQuality);
                    /**
                     * 出米率
                     */
                    mRecordRice.yieldRate = (recordRice.yieldRate + mRecordRice.yieldRate);
                    /**
                     * 出米率记录员
                     */
                    mRecordRice.yieldRateRecorder = recordRice.yieldRateRecorder
                }
            }
        }
        /**
         * 杂质
         */
        if(mRecordRice.impurityAverageValue){
            /**
             * 大样试验-试样质量
             */
            mRecordRice.largeMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordRice.largeMiscellaneousSampleQuality / length)
            /**
             * 大样试验-杂质
             */
            mRecordRice.detailImpurity = CommonUtils.formatDouble(mRecordRice.detailImpurity / length)
            /**
             * 大样杂质率
             */
            mRecordRice.detailResults = CommonUtils.formatDouble(mRecordRice.detailResults/ length)
            /**
             * 小样试验-试样质量
             */
            mRecordRice.smallMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordRice.smallMiscellaneousSampleQuality / length)
            /**
             * 小样试验-杂质
             */
            mRecordRice.smallSampleImpurity = CommonUtils.formatDouble(mRecordRice.smallSampleImpurity / length)
            /**
             * 小样杂质率
             */
            mRecordRice.sampleResults =CommonUtils.formatDouble(mRecordRice.sampleResults / length)
            /**
             * 总杂质率
             */
            mRecordRice.impurityResults = CommonUtils.formatDouble(mRecordRice.impurityResults / length)
        }
        /**
         * 出糙
         */
        if(mRecordRice.roughnessRateAverageValue){
            /**
             * 出糙率-试样质量
             */
            mRecordRice.roughSampleQuality = CommonUtils.formatDouble(mRecordRice.roughSampleQuality / length)
            /**
             * 完整糙米质量
             */
            mRecordRice.brownRiceQuality = CommonUtils.formatDouble(mRecordRice.brownRiceQuality / length)
            /**
             * 不完善糙米质量
             */
            mRecordRice.incompleteBrownRiceQuality = CommonUtils.formatDouble(mRecordRice.incompleteBrownRiceQuality / length)
            /**
             * 出糙率-结果
             */
            mRecordRice.rougheningResults = CommonUtils.formatDouble(mRecordRice.rougheningResults / length)
        }
        /***
         * 整精米率
         */
        if(mRecordRice.milledRiceAverageValue){
            /**
             * 整精米率-试样质量
             */
            mRecordRice.qualityOfMilledRiceSample = CommonUtils.formatDouble(mRecordRice.qualityOfMilledRiceSample / length)
            /**
             * 整精米质量
             */
            mRecordRice.headRiceQuality = CommonUtils.formatDouble(mRecordRice.headRiceQuality / length)
            /**
             * 整精米率-结果
             */
            mRecordRice.headRiceResult = CommonUtils.formatDouble(mRecordRice.headRiceResult / length)

        }
        /**
         * 谷外糙米
         */
        if(mRecordRice.ExternalValleyRoughnessAverageValue){
            /**
             * 谷外糙米-试样质量
             */
            mRecordRice.qualityOfBrownRiceSample = CommonUtils.formatDouble(mRecordRice.qualityOfBrownRiceSample / length)
            /**
             * 谷外糙米-糙米质量
             */
            mRecordRice.outsideBrownRiceQuality = CommonUtils.formatDouble(mRecordRice.outsideBrownRiceQuality / length)
            /**
             * 谷外糙米-结果
             */
            mRecordRice.brownRiceResult = CommonUtils.formatDouble(mRecordRice.brownRiceResult / length)
        }
        /**
         * 黄粒米
         */
        if(mRecordRice.YellowGrainRiceAverageValue){

            /**
             * 黄粒米-试样质量
             */
            mRecordRice.yellowGrainRiceSampleQuality = CommonUtils.formatDouble(mRecordRice.yellowGrainRiceSampleQuality / length)
            /**
             * 黄粒米质量
             */
            mRecordRice.yellowGrainRiceQuality = CommonUtils.formatDouble(mRecordRice.yellowGrainRiceQuality / length)
            /**
             * 黄粒米率
             */
            mRecordRice.yellowGrainRiceResult = CommonUtils.formatDouble(mRecordRice.yellowGrainRiceResult / length)
        }
        /**
         * 互混
         */
        if(mRecordRice.intermixingAverageValue){
            /**
             * 互混-试样质量
             */
            mRecordRice.massOfMixedSample = CommonUtils.formatDouble(mRecordRice.massOfMixedSample / length)
            /**
             * 异种粮质量
             */
            mRecordRice.mixedGrainQuality = CommonUtils.formatDouble(mRecordRice.mixedGrainQuality / length)
            /**
             * 互混-结果
             */
            mRecordRice.mixedGrainResult = CommonUtils.formatDouble(mRecordRice.mixedGrainResult / length)
        }
        /**
         * 出米率
         */
        if(mRecordRice.RiceOutputAverageValue){
            /**
             * 总稻谷量
             */
            mRecordRice.totalPaddyQuality = CommonUtils.formatDouble(mRecordRice.totalPaddyQuality / length)
            /**
             * 出米量
             */
            mRecordRice.riceQuality = CommonUtils.formatDouble(mRecordRice.riceQuality / length)
            /**
             * 出米率
             */
            mRecordRice.yieldRate = CommonUtils.formatDouble(mRecordRice.yieldRate / length)
        }
        /**
         * 添加
         */
        mRecordRice.save()
        return mRecordRice
    }


    /**
     * 小麦计算平均值
     */
    fun AverageValueRiceWheat(mRecordWheatList: List<RecordWheat>) : RecordWheat{
        val mRecordWheat = RecordWheat()
        var length = 0
        for (recordWheat in mRecordWheatList){
            /**
             * 是否选中
             */
            if(recordWheat.select){
                length ++
                /**
                 * 唯一识别码
                 */
                mRecordWheat.uniqueId = recordWheat.uniqueId

                /**
                 * 检测日期时间戳精确到毫秒 13位
                 */
                mRecordWheat.inspectionDate = TimeUtils.getNowMills()
                /**
                 * 设备码
                 */
                mRecordWheat.deviceId = recordWheat.deviceId

                if(!TextUtils.isEmpty(recordWheat.impurityRecorder)){
                    /**
                     * 是否杂质平均值
                     */
                    mRecordWheat.impurityAverageValue = true
                    /**
                     * 大样试验-试样质量
                     */
                    mRecordWheat.largeMiscellaneousSampleQuality = (recordWheat.largeMiscellaneousSampleQuality + mRecordWheat.largeMiscellaneousSampleQuality)
                    /**
                     * 大样试验-杂质
                     */
                    mRecordWheat.detailImpurity = (recordWheat.detailImpurity + mRecordWheat.detailImpurity);
                    /**
                     * 大样杂质率
                     */
                    mRecordWheat.detailResults = (recordWheat.detailResults + mRecordWheat.detailResults)
                    /**
                     * 小样试验-试样质量
                     */
                    mRecordWheat.smallMiscellaneousSampleQuality = (recordWheat.smallMiscellaneousSampleQuality + mRecordWheat.smallMiscellaneousSampleQuality)
                    /**
                     * 小样试验-杂质
                     */
                    mRecordWheat.smallSampleImpurity = (recordWheat.smallSampleImpurity + mRecordWheat.smallSampleImpurity)
                    /**
                     * 小样杂质率
                     */
                    mRecordWheat.sampleResults = (recordWheat.sampleResults + mRecordWheat.sampleResults)
                    /**
                     * 总杂质率
                     */
                    mRecordWheat.impurityResults = (recordWheat.impurityResults + mRecordWheat.impurityResults)
                    /**
                     * 矿物质质量
                     */
                    mRecordWheat.mineralQuality = (recordWheat.mineralQuality + mRecordWheat.mineralQuality)

                    /**
                     * 矿物质含量
                     */
                    mRecordWheat.mineralContent = (recordWheat.mineralContent + mRecordWheat.mineralContent)


                    /**
                     * 杂质记录员
                     */
                    mRecordWheat.impurityRecorder = recordWheat.impurityRecorder
                }
                if(!TextUtils.isEmpty(recordWheat.imperfectGrainRecorder)){
                    /**
                     * 是否不完善粒平均值
                     */
                    mRecordWheat.imperfectGrainValue = true


                    /**
                     * 不完善粒质量
                     */
                    mRecordWheat.imperfectGrainQuality = (recordWheat.imperfectGrainQuality + mRecordWheat.imperfectGrainQuality)
                    /**
                     * 不完善粒-结果
                     */
                    mRecordWheat.resultOfImperfectGrain = (recordWheat.resultOfImperfectGrain + mRecordWheat.resultOfImperfectGrain)


                    /**
                     * 虫蚀粒质量
                     */
                    mRecordWheat.insectBoredQuality = (recordWheat.insectBoredQuality + mRecordWheat.insectBoredQuality)
                    /**
                     * 虫蚀率-结果
                     */
                    mRecordWheat.insectBoredResult = (recordWheat.insectBoredResult + mRecordWheat.insectBoredResult)

                    /**
                     * 病斑粒质量
                     */
                    mRecordWheat.mottledQuality = (recordWheat.mottledQuality + mRecordWheat.mottledQuality)
                    /**
                     * 病斑率-结果
                     */
                    mRecordWheat.mottledResult = (recordWheat.mottledResult + mRecordWheat.mottledResult)

                    /**
                     * 破损粒质量
                     */
                    mRecordWheat.brokenQuality = (recordWheat.brokenQuality + mRecordWheat.brokenQuality)
                    /**
                     * 破损率-结果
                     */
                    mRecordWheat.brokenResult = (recordWheat.brokenResult + mRecordWheat.brokenResult)

                    /**
                     * 生芽粒重量
                     */
                    mRecordWheat.sproutWeight = (recordWheat.sproutWeight + mRecordWheat.sproutWeight)
                    /**
                     * 不生芽粒率-结果
                     */
                    mRecordWheat.sproutResult = (recordWheat.sproutResult + mRecordWheat.sproutResult)

                    /**
                     * 生霉粒重量
                     */
                    mRecordWheat.moldWeight = (recordWheat.moldWeight + mRecordWheat.moldWeight)
                    /**
                     * 生霉粒率-结果
                     */
                    mRecordWheat.moldResult = (recordWheat.moldResult + mRecordWheat.moldResult)

                    /**
                     * 赤霉病粒质量
                     */
                    mRecordWheat.qualityOfFusariumGraminearumGrain = (recordWheat.qualityOfFusariumGraminearumGrain + mRecordWheat.qualityOfFusariumGraminearumGrain)
                    /**
                     * 赤霉病粒-结果
                     */
                    mRecordWheat.scabGrainResults = (recordWheat.scabGrainResults + mRecordWheat.scabGrainResults)

                    /**
                     * 热损伤粒质量
                     */
                    mRecordWheat.thermalDamageGrainQuality = (recordWheat.thermalDamageGrainQuality + mRecordWheat.thermalDamageGrainQuality)
                    /**
                     * 热损伤粒 结果
                     */
                    mRecordWheat.thermalDamageGrain = (recordWheat.thermalDamageGrain + mRecordWheat.thermalDamageGrain)
                    /**
                     *  霉变粒质量
                     */
                    mRecordWheat.mildewGrainQuality = (recordWheat.mildewGrainQuality + mRecordWheat.mildewGrainQuality)
                    /**
                     * 霉变粒结果
                     */
                    mRecordWheat.mildewGrain = (recordWheat.mildewGrain + mRecordWheat.mildewGrain)

                    /**
                     * 不完善粒记录员
                     */
                    mRecordWheat.imperfectGrainRecorder = recordWheat.imperfectGrainRecorder
                }
                if(!TextUtils.isEmpty(recordWheat.glutenRecorder)){
                    /**
                     * 是否赤面筋平均值
                     */
                    mRecordWheat.glutenSampleValue = true
                    /**
                     * 面筋-试样质量
                     */
                    mRecordWheat.glutenSampleQuality = (recordWheat.glutenSampleQuality + mRecordWheat.glutenSampleQuality)
                    /**
                     * 湿面筋质量
                     */
                    mRecordWheat.wetGlutenQuality = (recordWheat.wetGlutenQuality + mRecordWheat.wetGlutenQuality)
                    /**
                     * 湿面筋含量 %
                     */
                    mRecordWheat.wetGlutenResult = (recordWheat.wetGlutenResult + mRecordWheat.wetGlutenResult)
                    /**
                     * 干面筋质量
                     */
                    mRecordWheat.dryGlutenQuality = (recordWheat.dryGlutenQuality + mRecordWheat.dryGlutenQuality)
                    /**
                     * 干面筋含量 %
                     */
                    mRecordWheat.dryGlutenResult = (recordWheat.dryGlutenResult + mRecordWheat.dryGlutenResult)
                    /**
                     *面筋吸水率结果
                     */
                    mRecordWheat.glutenWaterAbsorptionResults = (recordWheat.glutenWaterAbsorptionResults + mRecordWheat.glutenWaterAbsorptionResults)
                    /**
                     * 面筋记录员
                     */
                    mRecordWheat.glutenRecorder = recordWheat.glutenRecorder
                }
                if(!TextUtils.isEmpty(recordWheat.densityRecorder)){
                    /**
                     * 是否容重平均值
                     */
                    mRecordWheat.densityAverageValue = true
                    /**
                     * 容重-质量
                     */
                    mRecordWheat.densityQuality = (recordWheat.densityQuality + mRecordWheat.densityQuality)
                    /**
                     * 容重-结果
                     */
                    mRecordWheat.densityResult = (recordWheat.densityResult + mRecordWheat.densityResult)
                    /**
                     * 容重记录员
                     */
                    mRecordWheat.densityRecorder = recordWheat.densityRecorder

                }


            }
        }
        /**
         * 杂质
         */
        if(mRecordWheat.impurityAverageValue){
            /**
             * 大样试验-试样质量
             */
            mRecordWheat.largeMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordWheat.largeMiscellaneousSampleQuality / length)
            /**
             * 大样试验-杂质
             */
            mRecordWheat.detailImpurity = CommonUtils.formatDouble(mRecordWheat.detailImpurity / length)
            /**
             * 大样杂质率
             */
            mRecordWheat.detailResults = CommonUtils.formatDouble(mRecordWheat.detailResults/ length)
            /**
             * 小样试验-试样质量
             */
            mRecordWheat.smallMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordWheat.smallMiscellaneousSampleQuality / length)
            /**
             * 小样试验-杂质
             */
            mRecordWheat.smallSampleImpurity = CommonUtils.formatDouble(mRecordWheat.smallSampleImpurity / length)
            /**
             * 小样杂质率
             */
            mRecordWheat.sampleResults =CommonUtils.formatDouble(mRecordWheat.sampleResults / length)
            /**
             * 矿物质质量
             */
            mRecordWheat.mineralQuality = CommonUtils.formatDouble(mRecordWheat.mineralQuality / length)

            /**
             * 矿物质含量
             */
            mRecordWheat.mineralContent = CommonUtils.formatDouble(mRecordWheat.mineralContent / length)
            /**
             * 总杂质率
             */
            mRecordWheat.impurityResults = CommonUtils.formatDouble(mRecordWheat.impurityResults / length)
        }
        /**
         * 不完善粒
         */
        if(mRecordWheat.imperfectGrainValue){
            /**
             * 不完善粒质量
             */
            mRecordWheat.imperfectGrainQuality = CommonUtils.formatDouble(mRecordWheat.imperfectGrainQuality / length)
            /**
             * 不完善粒-结果
             */
            mRecordWheat.resultOfImperfectGrain = CommonUtils.formatDouble(mRecordWheat.resultOfImperfectGrain / length)



            /**
             * 虫蚀粒质量
             */
            mRecordWheat.insectBoredQuality = CommonUtils.formatDouble(mRecordWheat.insectBoredQuality / length)
            /**
             * 虫蚀率-结果
             */
            mRecordWheat.insectBoredResult = CommonUtils.formatDouble(mRecordWheat.insectBoredResult / length)

            /**
             * 病斑粒质量
             */
            mRecordWheat.mottledQuality = CommonUtils.formatDouble(mRecordWheat.mottledQuality / length)
            /**
             * 病斑率-结果
             */
            mRecordWheat.mottledResult = CommonUtils.formatDouble(mRecordWheat.mottledResult / length)

            /**
             * 破损粒质量
             */
            mRecordWheat.brokenQuality = CommonUtils.formatDouble(mRecordWheat.brokenQuality / length)
            /**
             * 破损率-结果
             */
            mRecordWheat.brokenResult = CommonUtils.formatDouble(mRecordWheat.brokenResult / length)

            /**
             * 生芽粒重量
             */
            mRecordWheat.sproutWeight = CommonUtils.formatDouble(mRecordWheat.sproutWeight / length)
            /**
             * 不生芽粒率-结果
             */
            mRecordWheat.sproutResult = CommonUtils.formatDouble(mRecordWheat.sproutResult / length)

            /**
             * 生霉粒重量
             */
            mRecordWheat.moldWeight = CommonUtils.formatDouble(mRecordWheat.moldWeight / length)
            /**
             * 生霉粒率-结果
             */
            mRecordWheat.moldResult = CommonUtils.formatDouble(mRecordWheat.moldResult / length)

            /**
             * 赤霉病粒质量
             */
            mRecordWheat.qualityOfFusariumGraminearumGrain = CommonUtils.formatDouble(mRecordWheat.qualityOfFusariumGraminearumGrain / length)
            /**
             * 赤霉病粒-结果
             */
            mRecordWheat.scabGrainResults = CommonUtils.formatDouble(mRecordWheat.scabGrainResults / length)

            /**
             * 热损伤粒质量
             */
            mRecordWheat.thermalDamageGrainQuality = CommonUtils.formatDouble(mRecordWheat.thermalDamageGrainQuality / length)
            /**
             * 热损伤粒 结果
             */
            mRecordWheat.thermalDamageGrain = CommonUtils.formatDouble(mRecordWheat.thermalDamageGrain / length)

            /**
             *  霉变粒质量
             */
            mRecordWheat.mildewGrainQuality = CommonUtils.formatDouble(mRecordWheat.mildewGrainQuality / length)
            /**
             * 霉变粒结果
             */
            mRecordWheat.mildewGrain = CommonUtils.formatDouble(mRecordWheat.mildewGrain / length)


        }
        /**
         * 面筋
         */
        if(mRecordWheat.glutenSampleValue){
            /**
             * 面筋-试样质量
             */
            mRecordWheat.glutenSampleQuality = CommonUtils.formatDouble(mRecordWheat.glutenSampleQuality / length)
            /**
             * 湿面筋质量
             */
            mRecordWheat.wetGlutenQuality = CommonUtils.formatDouble(mRecordWheat.wetGlutenQuality  / length)
            /**
             * 湿面筋含量 %
             */
            mRecordWheat.wetGlutenResult = CommonUtils.formatDouble(mRecordWheat.wetGlutenResult  / length)
            /**
             * 干面筋质量
             */
            mRecordWheat.dryGlutenQuality = CommonUtils.formatDouble(mRecordWheat.dryGlutenQuality  / length)
            /**
             * 干面筋含量 %
             */
            mRecordWheat.dryGlutenResult = CommonUtils.formatDouble(mRecordWheat.dryGlutenResult  / length)
            /**
             *面筋吸水率结果
             */
            mRecordWheat.glutenWaterAbsorptionResults = CommonUtils.formatDouble(mRecordWheat.glutenWaterAbsorptionResults  / length)
        }

        /**
         * 容重
         */
        if(mRecordWheat.densityAverageValue){
            /**
             * 容重-质量
             */
            mRecordWheat.densityQuality = CommonUtils.formatDouble(mRecordWheat.densityQuality / length)
            /**
             * 容重-结果
             */
            mRecordWheat.densityResult = CommonUtils.formatDouble(mRecordWheat.densityResult  / length)
        }


        /**
         * 添加
         */
        mRecordWheat.save()
        
        return mRecordWheat
    }

    /**
     * 玉米计算平均值
     */
    fun AverageValueRecordCorn(mRecordCornList: List<RecordCorn>, mSubclass : String) : RecordCorn{
        var mRecordCorn = RecordCorn()
        var length = 0
        for (recordRice in mRecordCornList) {
            /**
             * 是否选中
             */
            if (recordRice.select) {
                length++
                /**
                 * 唯一识别码
                 */
                mRecordCorn.uniqueId = recordRice.uniqueId

                /**
                 * 检测日期时间戳精确到毫秒 13位
                 */
                mRecordCorn.inspectionDate = TimeUtils.getNowMills()
                /**
                 * 设备码
                 */
                mRecordCorn.deviceId = recordRice.deviceId
                if(!TextUtils.isEmpty(recordRice.impurityRecorder)){
                    /**
                     * 是否杂质平均值
                     */
                    mRecordCorn.impurityAverageValue = true
                    /**
                     * 大样试验-试样质量
                     */
                    mRecordCorn.largeMiscellaneousSampleQuality = (recordRice.largeMiscellaneousSampleQuality + mRecordCorn.largeMiscellaneousSampleQuality)
                    /**
                     * 大样试验-杂质
                     */
                    mRecordCorn.detailImpurity = (recordRice.detailImpurity + mRecordCorn.detailImpurity);
                    /**
                     * 大样杂质率
                     */
                    mRecordCorn.detailResults = (recordRice.detailResults + mRecordCorn.detailResults)
                    /**
                     * 小样试验-试样质量
                     */
                    mRecordCorn.smallMiscellaneousSampleQuality = (recordRice.smallMiscellaneousSampleQuality + mRecordCorn.smallMiscellaneousSampleQuality)
                    /**
                     * 小样试验-杂质
                     */
                    mRecordCorn.smallSampleImpurity = (recordRice.smallSampleImpurity + mRecordCorn.smallSampleImpurity)
                    /**
                     * 小样杂质率
                     */
                    mRecordCorn.sampleResults = (recordRice.sampleResults + mRecordCorn.sampleResults)
                    /**
                     * 总杂质率
                     */
                    mRecordCorn.impurityResults = (recordRice.impurityResults + mRecordCorn.impurityResults)
                    /**
                     * 杂质记录员
                     */
                    mRecordCorn.impurityRecorder = recordRice.impurityRecorder
                }
                if(!TextUtils.isEmpty(recordRice.imperfectGrainRecorder)){
                    /**
                     * 是否不完善粒平均值
                     */
                    mRecordCorn.imperfectGrainValue =true
                    /**
                     * 不完善粒质量
                     */
                    mRecordCorn.imperfectGrainQuality = (recordRice.imperfectGrainQuality + mRecordCorn.imperfectGrainQuality)
                    /**
                     * 不完善粒-结果
                     */
                    mRecordCorn.resultOfImperfectGrain = (recordRice.resultOfImperfectGrain + mRecordCorn.resultOfImperfectGrain)






                    /**
                     * 虫蚀粒质量
                     */
                    mRecordCorn.insectBoredQuality = (recordRice.insectBoredQuality + mRecordCorn.insectBoredQuality)
                    /**
                     * 虫蚀率-结果
                     */
                    mRecordCorn.insectBoredResult = (recordRice.insectBoredResult + mRecordCorn.insectBoredResult)

                    /**
                     * 病斑粒质量
                     */
                    mRecordCorn.mottledQuality = (recordRice.mottledQuality + mRecordCorn.mottledQuality)
                    /**
                     * 病斑率-结果
                     */
                    mRecordCorn.mottledResult = (recordRice.mottledResult + mRecordCorn.mottledResult)

                    /**
                     * 破损粒质量
                     */
                    mRecordCorn.brokenQuality = (recordRice.brokenQuality + mRecordCorn.brokenQuality)
                    /**
                     * 破损率-结果
                     */
                    mRecordCorn.brokenResult = (recordRice.brokenResult + mRecordCorn.brokenResult)

                    /**
                     * 生芽粒重量
                     */
                    mRecordCorn.sproutWeight = (recordRice.sproutWeight + mRecordCorn.sproutWeight)
                    /**
                     * 不生芽粒率-结果
                     */
                    mRecordCorn.sproutResult = (recordRice.sproutResult + mRecordCorn.sproutResult)

                    /**
                     * 生霉粒重量
                     */
                    mRecordCorn.moldWeight = (recordRice.moldWeight + mRecordCorn.moldWeight)
                    /**
                     * 生霉粒率-结果
                     */
                    mRecordCorn.moldResult = (recordRice.moldResult + mRecordCorn.moldResult)


                    /**
                     * 热损伤粒质量
                     */
                    mRecordCorn.thermalDamageGrainQuality = (recordRice.thermalDamageGrainQuality + mRecordCorn.thermalDamageGrainQuality)
                    /**
                     * 热损伤粒结果
                     */
                    mRecordCorn.thermalDamageGrain = (recordRice.thermalDamageGrain + mRecordCorn.thermalDamageGrain)

                    /**
                     * 霉变粒质量
                     */
                    mRecordCorn.mildewGrainQuality = (recordRice.mildewGrainQuality + mRecordCorn.mildewGrainQuality)
                    /**
                     * 霉变粒结果
                     */
                    mRecordCorn.mildewGrain = (recordRice.mildewGrain + mRecordCorn.mildewGrain)


                    /**
                     * 不完善粒记录员
                     */
                    mRecordCorn.imperfectGrainRecorder = recordRice.imperfectGrainRecorder
                }
            }
        }
        /**
         * 杂质
         */
        if(mRecordCorn.impurityAverageValue){
            /**
             * 大样试验-试样质量
             */
            mRecordCorn.largeMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordCorn.largeMiscellaneousSampleQuality / length)
            /**
             * 大样试验-杂质
             */
            mRecordCorn.detailImpurity = CommonUtils.formatDouble(mRecordCorn.detailImpurity / length)
            /**
             * 大样杂质率
             */
            mRecordCorn.detailResults = CommonUtils.formatDouble(mRecordCorn.detailResults/ length)
            /**
             * 小样试验-试样质量
             */
            mRecordCorn.smallMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordCorn.smallMiscellaneousSampleQuality / length)
            /**
             * 小样试验-杂质
             */
            mRecordCorn.smallSampleImpurity = CommonUtils.formatDouble(mRecordCorn.smallSampleImpurity / length)
            /**
             * 小样杂质率
             */
            mRecordCorn.sampleResults =CommonUtils.formatDouble(mRecordCorn.sampleResults / length)
            /**
             * 总杂质率
             */
            mRecordCorn.impurityResults = CommonUtils.formatDouble(mRecordCorn.impurityResults / length)
        }
        /**
         * 不完善粒
         */
        if(mRecordCorn.imperfectGrainValue){
            /**
             * 不完善粒质量
             */
            mRecordCorn.imperfectGrainQuality = CommonUtils.formatDouble(mRecordCorn.imperfectGrainQuality / length)
            /**
             * 不完善粒-结果
             */
            mRecordCorn.resultOfImperfectGrain = CommonUtils.formatDouble(mRecordCorn.resultOfImperfectGrain / length)


            /**
             * 虫蚀粒质量
             */
            mRecordCorn.insectBoredQuality = CommonUtils.formatDouble(mRecordCorn.insectBoredQuality / length)
            /**
             * 虫蚀率-结果
             */
            mRecordCorn.insectBoredResult = CommonUtils.formatDouble(mRecordCorn.insectBoredResult / length)

            /**
             * 病斑粒质量
             */
            mRecordCorn.mottledQuality = CommonUtils.formatDouble(mRecordCorn.mottledQuality / length)
            /**
             * 病斑率-结果
             */
            mRecordCorn.mottledResult = CommonUtils.formatDouble(mRecordCorn.mottledResult / length)

            /**
             * 破损粒质量
             */
            mRecordCorn.brokenQuality = CommonUtils.formatDouble(mRecordCorn.brokenQuality / length)
            /**
             * 破损率-结果
             */
            mRecordCorn.brokenResult = CommonUtils.formatDouble(mRecordCorn.brokenResult / length)

            /**
             * 生芽粒重量
             */
            mRecordCorn.sproutWeight = CommonUtils.formatDouble(mRecordCorn.sproutWeight / length)
            /**
             * 不生芽粒率-结果
             */
            mRecordCorn.sproutResult = CommonUtils.formatDouble(mRecordCorn.sproutResult / length)

            /**
             * 生霉粒重量
             */
            mRecordCorn.moldWeight = CommonUtils.formatDouble(mRecordCorn.moldWeight / length)
            /**
             * 生霉粒率-结果
             */
            mRecordCorn.moldResult = CommonUtils.formatDouble(mRecordCorn.moldResult / length)
            /**
             * 热损伤粒质量
             */
            mRecordCorn.thermalDamageGrainQuality = CommonUtils.formatDouble(mRecordCorn.thermalDamageGrainQuality / length)
            /**
             * 热损伤粒结果
             */
            mRecordCorn.thermalDamageGrain = CommonUtils.formatDouble(mRecordCorn.thermalDamageGrain / length)
            /**
             * 霉变粒质量
             */
            mRecordCorn.mildewGrainQuality = CommonUtils.formatDouble(mRecordCorn.mildewGrainQuality / length)
            /**
             * 霉变粒结果
             */
            mRecordCorn.mildewGrain = CommonUtils.formatDouble(mRecordCorn.mildewGrain / length)
        }
        /**
         * 添加
         */
        mRecordCorn.save()

        return mRecordCorn
    }


    /**
     * 大米计算平均值
     */
    fun AverageValueRecordDaMi(mRecordDaMiList: List<RecordDaMi>, mSubclass : String) : RecordDaMi{
        var mRecordDaMi = RecordDaMi()
        var length = 0
        for (recordDaMi in mRecordDaMiList) {
            /**
             * 是否选中
             */
            if (recordDaMi.select) {
                length++
                /**
                 * 唯一识别码
                 */
                mRecordDaMi.uniqueId = recordDaMi.uniqueId

                /**
                 * 检测日期时间戳精确到毫秒 13位
                 */
                mRecordDaMi.inspectionDate = TimeUtils.getNowMills()
                /**
                 * 设备码
                 */
                mRecordDaMi.deviceId = recordDaMi.deviceId
                if(!TextUtils.isEmpty(recordDaMi.impurityRecorder)){
                    /**
                     * 是否杂质平均值
                     */
                    mRecordDaMi.impurityAverageValue = true
                    /**
                     * 大米-试样质量
                     */
                    mRecordDaMi.riceSampleQuality = (recordDaMi.riceSampleQuality + mRecordDaMi.riceSampleQuality)
                    /**
                     * 大米-杂质
                     */
                    mRecordDaMi.riceImpurity = (recordDaMi.riceImpurity + mRecordDaMi.riceImpurity)
                    /**
                     * 杂质率
                     */
                    mRecordDaMi.impurityResults = (recordDaMi.impurityResults + mRecordDaMi.impurityResults)
                    /**
                     * 杂质记录员
                     */
                    mRecordDaMi.impurityRecorder = recordDaMi.impurityRecorder
                }
                if(!TextUtils.isEmpty(recordDaMi.imperfectGrainRecorder)){
                    /**
                     * 是否不完善粒平均值
                     */
                    mRecordDaMi.imperfectGrainValue = true
                    /**
                     * 不完善粒-试样质量
                     */
                    mRecordDaMi.qualityOfImperfectGrainSample = (recordDaMi.qualityOfImperfectGrainSample + mRecordDaMi.qualityOfImperfectGrainSample)

                    /**
                     * 不完善粒质量
                     *
                     */
                    mRecordDaMi.imperfectGrainQuality = (recordDaMi.imperfectGrainQuality + mRecordDaMi.imperfectGrainQuality)

                    /**
                     * 不完善粒-结果
                     */
                    mRecordDaMi.resultOfImperfectGrain = (recordDaMi.resultOfImperfectGrain + mRecordDaMi.resultOfImperfectGrain)



                    /**
                    * 未熟粒重量
                    */
                    mRecordDaMi.immatureBrokenGrainQuality = (recordDaMi.immatureBrokenGrainQuality + mRecordDaMi.immatureBrokenGrainQuality)
                    /**
                     * 虫蚀率-结果
                     */
                    mRecordDaMi.immatureGrainResult = (recordDaMi.immatureGrainResult + mRecordDaMi.immatureGrainResult)

                    /**
                     *  虫蚀粒质量
                     */
                    mRecordDaMi.insectBoredQuality = (recordDaMi.insectBoredQuality + mRecordDaMi.insectBoredQuality)
                    /**
                     * 虫蚀率-结果
                     */
                    mRecordDaMi.insectBoredResult = (recordDaMi.insectBoredResult + mRecordDaMi.insectBoredResult)

                    /**
                     * 病斑粒质量
                     */
                    mRecordDaMi.mottledQuality = (recordDaMi.mottledQuality + mRecordDaMi.mottledQuality)
                    /**
                     * 病斑率-结果
                     */
                    mRecordDaMi.mottledResult = (recordDaMi.mottledResult + mRecordDaMi.mottledResult)

                    /**
                     * 生霉粒重量
                     */
                    mRecordDaMi.moldWeight = (recordDaMi.moldWeight + mRecordDaMi.moldWeight)
                    /**
                     * 生霉粒率-结果
                     */
                    mRecordDaMi.moldResult = (recordDaMi.moldResult + mRecordDaMi.moldResult)

                    /**
                     * 糙米粒重量
                     */
                    mRecordDaMi.incompleteBrownRiceQuality = (recordDaMi.incompleteBrownRiceQuality + mRecordDaMi.incompleteBrownRiceQuality)
                    /**
                     * 糙米粒率-结果+
                     */
                    mRecordDaMi.rougheningResults = (recordDaMi.rougheningResults + mRecordDaMi.rougheningResults)



                    /**
                     *不完善粒记录员
                     */
                    mRecordDaMi.imperfectGrainRecorder = recordDaMi.imperfectGrainRecorder
                }
                if(!TextUtils.isEmpty(recordDaMi.brokenRiceRecorder)){
                    /**
                     * 是否碎米平均值
                     */
                    mRecordDaMi.qualityOfBrokenValue = true
                    /**
                     * 碎米-试样质量
                     */
                    mRecordDaMi.qualityOfBrokenRiceSample = (recordDaMi.qualityOfBrokenRiceSample + mRecordDaMi.qualityOfBrokenRiceSample)
                    /**
                     * 碎米质量
                     */
                    mRecordDaMi.brokenRiceQuality = (recordDaMi.brokenRiceQuality + mRecordDaMi.brokenRiceQuality)
                    /**
                     * 碎米率
                     */
                    mRecordDaMi.totalBrokenRice = (recordDaMi.totalBrokenRice + mRecordDaMi.totalBrokenRice)
                    /**
                     * 小碎米质量
                     */
                    mRecordDaMi.smallBrokenRiceQuality = (recordDaMi.smallBrokenRiceQuality + mRecordDaMi.smallBrokenRiceQuality)
                    /**
                     * 小碎米率
                     */
                    mRecordDaMi.smallBrokenRice = (recordDaMi.smallBrokenRice + mRecordDaMi.smallBrokenRice)
                    /**
                     * 小碎米记录员
                     */
                    mRecordDaMi.brokenRiceRecorder =recordDaMi.brokenRiceRecorder
                }
                if(!TextUtils.isEmpty(recordDaMi.yellowGrainRiceRecorder)){
                    /**
                     * 是否碎米平均值
                     */
                    mRecordDaMi.yellowGrainRiceSampleValue = true
                    /**
                     * 黄粒米-试样质量
                     */
                    mRecordDaMi.yellowGrainRiceSampleQuality = (recordDaMi.yellowGrainRiceSampleQuality + mRecordDaMi.yellowGrainRiceSampleQuality)
                    /**
                     * 黄粒米质量
                     */
                    mRecordDaMi.yellowGrainRiceQuality = (recordDaMi.yellowGrainRiceQuality + mRecordDaMi.yellowGrainRiceQuality)
                    /**
                     * 黄粒米率
                     */
                    mRecordDaMi.yellowGrainRiceResult = (recordDaMi.yellowGrainRiceResult + mRecordDaMi.yellowGrainRiceResult)
                    /**
                     * 黄粒米记录员
                     */
                    mRecordDaMi.yellowGrainRiceRecorder = recordDaMi.yellowGrainRiceRecorder
                }
                if(!TextUtils.isEmpty(recordDaMi.mixedGrainRecorder)){
                    /**
                     * 是否碎米平均值
                     */
                    mRecordDaMi.massOfMixedSampleValue = true
                    /**
                     * 互混-试样质量
                     */
                    mRecordDaMi.massOfMixedSample = (recordDaMi.massOfMixedSample + mRecordDaMi.massOfMixedSample);
                    /**
                     * 异种粮质量
                     */
                    mRecordDaMi.mixedGrainQuality = (recordDaMi.mixedGrainQuality + mRecordDaMi.mixedGrainQuality);
                    /**
                     * 互混-结果
                     */
                    mRecordDaMi.mixedGrainResult = (recordDaMi.mixedGrainResult + mRecordDaMi.mixedGrainResult);
                    /**
                     * 互混记录员
                     */
                    mRecordDaMi.mixedGrainRecorder = recordDaMi.mixedGrainRecorder
                }
            }
        }
        /**
         * 杂质
         */
        if(mRecordDaMi.impurityAverageValue){

            /**
             * 大米-试样质量
             */
            mRecordDaMi.riceSampleQuality = CommonUtils.formatDouble(mRecordDaMi.riceSampleQuality / length)
            /**
             * 大米-杂质
             */
            mRecordDaMi.riceImpurity = CommonUtils.formatDouble(mRecordDaMi.riceImpurity / length)
            /**
             * 杂质率
             */
            mRecordDaMi.impurityResults = CommonUtils.formatDouble(mRecordDaMi.impurityResults / length)
        }
        /**
         * 不完善粒
         */
        if(mRecordDaMi.imperfectGrainValue){
            /**
             * 不完善粒-试样质量
             */
            mRecordDaMi.qualityOfImperfectGrainSample = CommonUtils.formatDouble(mRecordDaMi.qualityOfImperfectGrainSample / length)
            /**
             * 不完善粒质量
             *
             */
            mRecordDaMi.imperfectGrainQuality = CommonUtils.formatDouble(mRecordDaMi.imperfectGrainQuality / length)
            /**
             * 不完善粒-结果
             */
            mRecordDaMi.resultOfImperfectGrain = CommonUtils.formatDouble(mRecordDaMi.resultOfImperfectGrain / length)


            /**
             * 未熟粒重量
             */
            mRecordDaMi.immatureBrokenGrainQuality = CommonUtils.formatDouble(mRecordDaMi.immatureBrokenGrainQuality / length)
            /**
             * 未熟粒率-结果
             */
            mRecordDaMi.immatureGrainResult = CommonUtils.formatDouble(mRecordDaMi.immatureGrainResult / length)
            /**
             * 虫蚀粒质量
             */
            mRecordDaMi.insectBoredQuality = CommonUtils.formatDouble(mRecordDaMi.insectBoredQuality / length)
            /**
             * 虫蚀率-结果
             */
            mRecordDaMi.insectBoredResult = CommonUtils.formatDouble(mRecordDaMi.insectBoredResult / length)

            /**
             * 病斑粒质量
             */
            mRecordDaMi.mottledQuality = CommonUtils.formatDouble(mRecordDaMi.mottledQuality / length)
            /**
             * 病斑率-结果
             */
            mRecordDaMi.mottledResult = CommonUtils.formatDouble(mRecordDaMi.mottledResult / length)
            /**
             * 生霉粒重量
             */
            mRecordDaMi.moldWeight = CommonUtils.formatDouble(mRecordDaMi.moldWeight / length)
            /**
             * 生霉粒率-结果
             */
            mRecordDaMi.moldResult = CommonUtils.formatDouble(mRecordDaMi.moldResult / length)

            /**
             * 糙米粒重量
             */
            mRecordDaMi.incompleteBrownRiceQuality = CommonUtils.formatDouble(mRecordDaMi.incompleteBrownRiceQuality / length)
            /**
             * 糙米粒率-结果+
             */
            mRecordDaMi.rougheningResults = CommonUtils.formatDouble(mRecordDaMi.rougheningResults / length)

        }
        /**
         * 碎米
         */
        if(mRecordDaMi.qualityOfBrokenValue){
            /**
             * 碎米-试样质量
             */
            mRecordDaMi.qualityOfBrokenRiceSample = CommonUtils.formatDouble(mRecordDaMi.qualityOfBrokenRiceSample / length)
            /**
             * 碎米质量
             */
            mRecordDaMi.brokenRiceQuality = CommonUtils.formatDouble(mRecordDaMi.brokenRiceQuality / length)
            /**
             * 碎米率
             */
            mRecordDaMi.totalBrokenRice = CommonUtils.formatDouble(mRecordDaMi.totalBrokenRice / length)
            /**
             * 小碎米质量
             */
            mRecordDaMi.smallBrokenRiceQuality = (CommonUtils.formatDouble(mRecordDaMi.smallBrokenRiceQuality / length));
            /**
             * 小碎米率
             */
            mRecordDaMi.smallBrokenRice = (CommonUtils.formatDouble(mRecordDaMi.smallBrokenRice / length));
        }
        /**
         * 黄粒米
         */
        if(mRecordDaMi.yellowGrainRiceSampleValue){
            /**
             * 黄粒米-试样质量
             */
            mRecordDaMi.yellowGrainRiceSampleQuality = CommonUtils.formatDouble(mRecordDaMi.yellowGrainRiceSampleQuality / length)
            /**
             * 黄粒米质量
             */
            mRecordDaMi.yellowGrainRiceQuality = CommonUtils.formatDouble(mRecordDaMi.yellowGrainRiceQuality / length)
            /**
             * 黄粒米率
             */
            mRecordDaMi.yellowGrainRiceResult = CommonUtils.formatDouble(mRecordDaMi.yellowGrainRiceResult / length)

        }
        /**
         * 互混
         */
        if(mRecordDaMi.massOfMixedSampleValue){

            /**
             * 互混-试样质量
             */
            mRecordDaMi.massOfMixedSample = CommonUtils.formatDouble(mRecordDaMi.massOfMixedSample / length)
            /**
             * 异种粮质量
             */
            mRecordDaMi.mixedGrainQuality = CommonUtils.formatDouble(mRecordDaMi.mixedGrainQuality / length)
            /**
             * 互混-结果
             */
            mRecordDaMi.mixedGrainResult = CommonUtils.formatDouble(mRecordDaMi.mixedGrainResult / length)
        }
        /**
         * 添加
         */
        mRecordDaMi.save()

        return mRecordDaMi
    }


    /**
     * 大豆计算平均值
     */
    fun AverageValueRecordSoybean(mRecordSoybeanList: List<RecordSoybean>, mSubclass : String) : RecordSoybean {
        var mRecordSoybean = RecordSoybean()
        var length = 0
        for (recordSoybean in mRecordSoybeanList) {
            /**
             * 是否选中
             */
            if (recordSoybean.select) {
                length++
                /**
                 * 唯一识别码
                 */
                mRecordSoybean.uniqueId = recordSoybean.uniqueId

                /**
                 * 检测日期时间戳精确到毫秒 13位
                 */
                mRecordSoybean.inspectionDate = TimeUtils.getNowMills()
                /**
                 * 设备码
                 */
                mRecordSoybean.deviceId = recordSoybean.deviceId
                if(!TextUtils.isEmpty(recordSoybean.impurityRecorder)){
                    /**
                     * 是否杂质平均值
                     */
                    mRecordSoybean.impurityAverageValue = true
                    /**
                     * 大样试验-试样质量
                     */
                    mRecordSoybean.largeMiscellaneousSampleQuality = (recordSoybean.largeMiscellaneousSampleQuality + mRecordSoybean.largeMiscellaneousSampleQuality)
                    /**
                     * 大样试验-杂质
                     */
                    mRecordSoybean.detailImpurity = (recordSoybean.detailImpurity + mRecordSoybean.detailImpurity);
                    /**
                     * 大样杂质率
                     */
                    mRecordSoybean.detailResults = (recordSoybean.detailResults + mRecordSoybean.detailResults)
                    /**
                     * 小样试验-试样质量
                     */
                    mRecordSoybean.smallMiscellaneousSampleQuality = (recordSoybean.smallMiscellaneousSampleQuality + mRecordSoybean.smallMiscellaneousSampleQuality)
                    /**
                     * 小样试验-杂质
                     */
                    mRecordSoybean.smallSampleImpurity = (recordSoybean.smallSampleImpurity + mRecordSoybean.smallSampleImpurity)
                    /**
                     * 小样杂质率
                     */
                    mRecordSoybean.sampleResults = (recordSoybean.sampleResults + mRecordSoybean.sampleResults)
                    /**
                     * 总杂质率
                     */
                    mRecordSoybean.impurityResults = (recordSoybean.impurityResults + mRecordSoybean.impurityResults)
                    /**
                     * 杂质记录员
                     */
                    mRecordSoybean.impurityRecorder = recordSoybean.impurityRecorder
                }
                if(!TextUtils.isEmpty(recordSoybean.damagedGrainRecorder)){
                    /**
                     * 是否损伤粒平均值
                     */
                    mRecordSoybean.damagedGrainValue = true
                    /**
                     * 损伤粒(含热损伤粒)质量
                     */
                    mRecordSoybean.damagedGrainQuality = (recordSoybean.damagedGrainQuality + mRecordSoybean.damagedGrainQuality);

                    /**
                     * 损伤粒率
                     */
                    mRecordSoybean.damagedGrainResult = (recordSoybean.damagedGrainResult + mRecordSoybean.damagedGrainResult);

                    /**
                     * 损伤粒记录员
                     */
                    mRecordSoybean.damagedGrainRecorder = recordSoybean.damagedGrainRecorder
                }
                if(!TextUtils.isEmpty(recordSoybean.thermalDamageGrainRecorder)){
                    /**
                     * 是否热损伤粒平均值
                     */
                    mRecordSoybean.thermalDamageValue = true
                    /**
                     * 热损伤粒质量
                     */
                    mRecordSoybean.thermalDamageGrainQuality = (recordSoybean.thermalDamageGrainQuality + mRecordSoybean.thermalDamageGrainQuality);

                    /**
                     * 热损伤粒率
                     */
                    mRecordSoybean.thermalDamageGrain = (recordSoybean.thermalDamageGrain + mRecordSoybean.thermalDamageGrain);

                    /**
                     * 热损伤粒记录员
                     */
                    mRecordSoybean.thermalDamageGrainRecorder = recordSoybean.thermalDamageGrainRecorder
                }
                if(!TextUtils.isEmpty(recordSoybean.wholeGrainRecorder)){
                    /**
                     * 是否未熟粒平均值
                     */
                    mRecordSoybean.immatureBrokenGrainValue = true
                    /**
                     * 未熟粒、破损粒质量
                     */
                    mRecordSoybean.immatureBrokenGrainQuality = (recordSoybean.immatureBrokenGrainQuality + mRecordSoybean.immatureBrokenGrainQuality);
                    /**
                     * 完整粒率
                     */
                    mRecordSoybean.wholeGrainRate = (recordSoybean.wholeGrainRate + mRecordSoybean.wholeGrainRate);
                    /**
                     * 完整粒记录员
                     */
                    mRecordSoybean.wholeGrainRecorder = recordSoybean.wholeGrainRecorder
                }
            }
        }
        /**
         * 杂质
         */
        if(mRecordSoybean.impurityAverageValue){
            /**
             * 大样试验-试样质量
             */
            mRecordSoybean.largeMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordSoybean.largeMiscellaneousSampleQuality / length)
            /**
             * 大样试验-杂质
             */
            mRecordSoybean.detailImpurity = CommonUtils.formatDouble(mRecordSoybean.detailImpurity / length)
            /**
             * 大样杂质率
             */
            mRecordSoybean.detailResults = CommonUtils.formatDouble(mRecordSoybean.detailResults/ length)
            /**
             * 小样试验-试样质量
             */
            mRecordSoybean.smallMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordSoybean.smallMiscellaneousSampleQuality / length)
            /**
             * 小样试验-杂质
             */
            mRecordSoybean.smallSampleImpurity = CommonUtils.formatDouble(mRecordSoybean.smallSampleImpurity / length)
            /**
             * 小样杂质率
             */
            mRecordSoybean.sampleResults =CommonUtils.formatDouble(mRecordSoybean.sampleResults / length)
            /**
             * 总杂质率
             */
            mRecordSoybean.impurityResults = CommonUtils.formatDouble(mRecordSoybean.impurityResults / length)
        }
        /**
         * 损伤粒率
         */
        if(mRecordSoybean.damagedGrainValue){
            /**
             * 损伤粒(含热损伤粒)质量
             */
            mRecordSoybean.damagedGrainQuality = CommonUtils.formatDouble(mRecordSoybean.damagedGrainQuality / length)

            /**
             * 损伤粒率
             */
            mRecordSoybean.damagedGrainResult = CommonUtils.formatDouble(mRecordSoybean.damagedGrainResult / length)

        }
        /**
         * 热损伤粒率
         */
        if(mRecordSoybean.thermalDamageValue){
            /**
             * 热损伤粒质量
             */
            mRecordSoybean.thermalDamageGrainQuality = CommonUtils.formatDouble(mRecordSoybean.thermalDamageGrainQuality / length)

            /**
             * 热损伤粒率
             */
            mRecordSoybean.thermalDamageGrain = CommonUtils.formatDouble(mRecordSoybean.thermalDamageGrain / length)
        }
        /**
         * 完整粒率
         */
        if(mRecordSoybean.immatureBrokenGrainValue){
            /**
             * 未熟粒、破损粒质量
             */
            mRecordSoybean.immatureBrokenGrainQuality = CommonUtils.formatDouble(mRecordSoybean.immatureBrokenGrainQuality / length)
            /**
             * 完整粒率
             */
            mRecordSoybean.wholeGrainRate = CommonUtils.formatDouble(mRecordSoybean.wholeGrainRate / length)
        }
        /**
         * 添加
         */
        mRecordSoybean.save()
        return mRecordSoybean
    }

    /**
     * 油菜籽计算平均值
     */
    fun AverageValueRecordRapeseed(mRecordRapeseedList: List<RecordRapeseed>, mSubclass : String) : RecordRapeseed{
        var mRecordRapeseed = RecordRapeseed()
        var length = 0
        for (recordRapeseed in mRecordRapeseedList) {
            /**
             * 是否选中
             */
            if (recordRapeseed.select) {
                length++
                /**
                 * 唯一识别码
                 */
                mRecordRapeseed.uniqueId = recordRapeseed.uniqueId

                /**
                 * 检测日期时间戳精确到毫秒 13位
                 */
                mRecordRapeseed.inspectionDate = TimeUtils.getNowMills()
                /**
                 * 设备码
                 */
                mRecordRapeseed.deviceId = recordRapeseed.deviceId
                if(!TextUtils.isEmpty(recordRapeseed.impurityRecorder)){
                    /**
                     * 是否杂质平均值
                     */
                    mRecordRapeseed.impurityAverageValue = true
                    /**
                     * 大样试验-试样质量
                     */
                    mRecordRapeseed.largeMiscellaneousSampleQuality = (recordRapeseed.largeMiscellaneousSampleQuality + mRecordRapeseed.largeMiscellaneousSampleQuality)
                    /**
                     * 大样试验-杂质
                     */
                    mRecordRapeseed.detailImpurity = (recordRapeseed.detailImpurity + mRecordRapeseed.detailImpurity);
                    /**
                     * 大样杂质率
                     */
                    mRecordRapeseed.detailResults = (recordRapeseed.detailResults + mRecordRapeseed.detailResults)
                    /**
                     * 小样试验-试样质量
                     */
                    mRecordRapeseed.smallMiscellaneousSampleQuality = (recordRapeseed.smallMiscellaneousSampleQuality + mRecordRapeseed.smallMiscellaneousSampleQuality)
                    /**
                     * 小样试验-杂质
                     */
                    mRecordRapeseed.smallSampleImpurity = (recordRapeseed.smallSampleImpurity + mRecordRapeseed.smallSampleImpurity)
                    /**
                     * 小样杂质率
                     */
                    mRecordRapeseed.sampleResults = (recordRapeseed.sampleResults + mRecordRapeseed.sampleResults)
                    /**
                     * 总杂质率
                     */
                    mRecordRapeseed.impurityResults = (recordRapeseed.impurityResults + mRecordRapeseed.impurityResults)
                    /**
                     * 杂质记录员
                     */
                    mRecordRapeseed.impurityRecorder = recordRapeseed.impurityRecorder
                }
                if(!TextUtils.isEmpty(recordRapeseed.sproutRecorder)){
                    /**
                     * 生芽粒平均值
                     */
                    mRecordRapeseed.sproutWeightValue = true

                    /**
                     * 生芽粒重量
                     */
                    mRecordRapeseed.sproutWeight = (recordRapeseed.sproutWeight + mRecordRapeseed.sproutWeight);
                    /**
                     * 生芽粒率-结果
                     */
                    mRecordRapeseed.sproutResult = (recordRapeseed.sproutResult + mRecordRapeseed.sproutResult);
                    /**
                     * 生芽粒率记录员
                     */
                    mRecordRapeseed.sproutRecorder = recordRapeseed.sproutRecorder
                }
                if(!TextUtils.isEmpty(recordRapeseed.moldRecorder)){
                    /**
                     * 生芽粒平均值
                     */
                    mRecordRapeseed.moldWeightValue = true
                    /**
                     * 生霉粒重量
                     */
                    mRecordRapeseed.moldWeight = (recordRapeseed.moldWeight + mRecordRapeseed.moldWeight);
                    /**
                     * 生霉粒率-结果
                     */
                    mRecordRapeseed.moldResult = (recordRapeseed.moldResult + mRecordRapeseed.moldResult);
                    /**
                     * 生霉粒率记录员
                     */
                    mRecordRapeseed.moldRecorder = recordRapeseed.moldRecorder
                }
                if(!TextUtils.isEmpty(recordRapeseed.thermalDamageNumberRecorder)){
                    /**
                     * 热损伤粒平均值
                     */
                    mRecordRapeseed.thermalDamageValue = true
                    /**
                     * 热损伤粒数
                     */
                    mRecordRapeseed.thermalDamageNumber1 = (recordRapeseed.thermalDamageNumber1 + mRecordRapeseed.thermalDamageNumber1);

                    mRecordRapeseed.thermalDamageNumber2 = (recordRapeseed.thermalDamageNumber2 + mRecordRapeseed.thermalDamageNumber2);
                    /**
                     * 热损伤粒-结果
                     */
                    mRecordRapeseed.thermalDamageGrain = (recordRapeseed.thermalDamageGrain + mRecordRapeseed.thermalDamageGrain);

                    /**
                     * 热损伤粒数记录员
                     */
                    mRecordRapeseed.thermalDamageNumberRecorder = recordRapeseed.thermalDamageNumberRecorder
                }
                if(!TextUtils.isEmpty(recordRapeseed.immatureGrainNumberRecorder)){
                    /**
                     * 未熟粒数平均值
                     */
                    mRecordRapeseed.immatureGrainValue = true
                    /**
                     * 未熟粒数 检测可能有两次
                     */
                    mRecordRapeseed.immatureGrainNumber1 = (recordRapeseed.immatureGrainNumber1 + mRecordRapeseed.immatureGrainNumber1);

                    mRecordRapeseed.immatureGrainNumber2 = (recordRapeseed.immatureGrainNumber2 + mRecordRapeseed.immatureGrainNumber2);
                    /**
                     * 未熟粒-结果
                     */
                    mRecordRapeseed.immatureGrainResult = (recordRapeseed.immatureGrainResult + mRecordRapeseed.immatureGrainResult);

                    /**
                     * 未熟粒数记录员
                     */
                    mRecordRapeseed.immatureGrainNumberRecorder = recordRapeseed.immatureGrainNumberRecorder
                }
            }
        }
        /**
         * 杂质
         */
        if(mRecordRapeseed.impurityAverageValue){
            /**
             * 大样试验-试样质量
             */
            mRecordRapeseed.largeMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordRapeseed.largeMiscellaneousSampleQuality / length)
            /**
             * 大样试验-杂质
             */
            mRecordRapeseed.detailImpurity = CommonUtils.formatDouble(mRecordRapeseed.detailImpurity / length)
            /**
             * 大样杂质率
             */
            mRecordRapeseed.detailResults = CommonUtils.formatDouble(mRecordRapeseed.detailResults/ length)
            /**
             * 小样试验-试样质量
             */
            mRecordRapeseed.smallMiscellaneousSampleQuality = CommonUtils.formatDouble(mRecordRapeseed.smallMiscellaneousSampleQuality / length)
            /**
             * 小样试验-杂质
             */
            mRecordRapeseed.smallSampleImpurity = CommonUtils.formatDouble(mRecordRapeseed.smallSampleImpurity / length)
            /**
             * 小样杂质率
             */
            mRecordRapeseed.sampleResults =CommonUtils.formatDouble(mRecordRapeseed.sampleResults / length)
            /**
             * 总杂质率
             */
            mRecordRapeseed.impurityResults = CommonUtils.formatDouble(mRecordRapeseed.impurityResults / length)
        }
        /**
         * 生芽粒
         */
        if(mRecordRapeseed.sproutWeightValue){
            /**
             * 生芽粒重量
             */
            mRecordRapeseed.sproutWeight = (CommonUtils.formatDouble(mRecordRapeseed.sproutWeight / length));
            /**
             * 生芽粒率-结果
             */
            mRecordRapeseed.sproutResult = (CommonUtils.formatDouble(mRecordRapeseed.sproutResult / length));

        }
        /**
         * 生霉粒
         */
        if(mRecordRapeseed.moldWeightValue){
            /**
             * 生霉粒重量
             */
            mRecordRapeseed.moldWeight = (CommonUtils.formatDouble(mRecordRapeseed.moldWeight / length));
            /**
             * 生霉粒率-结果
             */
            mRecordRapeseed.moldResult = (CommonUtils.formatDouble(mRecordRapeseed.moldResult / length));
        }
        /**
         * 热损伤粒
         */
        if(mRecordRapeseed.thermalDamageValue){
            /**
             * 热损伤粒数
             */
            mRecordRapeseed.thermalDamageNumber1 = (mRecordRapeseed.thermalDamageNumber1 / length);

            mRecordRapeseed.thermalDamageNumber2 = (mRecordRapeseed.thermalDamageNumber2 / length);
            /**
             * 热损伤粒-结果
             */
            mRecordRapeseed.thermalDamageGrain = (mRecordRapeseed.thermalDamageGrain / length);
        }
        /**
         * 未熟粒
         */
        if(mRecordRapeseed.immatureGrainValue){
            /**
             * 未熟粒数 检测可能有两次
             */
            mRecordRapeseed.immatureGrainNumber1 = (mRecordRapeseed.immatureGrainNumber1 / length);

            mRecordRapeseed.immatureGrainNumber2 = (mRecordRapeseed.immatureGrainNumber2 / length);
            /**
             * 未熟粒-结果
             */
            mRecordRapeseed.immatureGrainResult = (mRecordRapeseed.immatureGrainResult / length);
        }
        /**
         * 添加
         */
        mRecordRapeseed.save()

        return mRecordRapeseed
    }
}